﻿using CastingWellEquipmentGUI.Model;
using CastingWellEquipmentGUI.ViewModel.Common.Command;
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Messaging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CastingWellEquipmentGUI.ViewModel.Modal
{
    public class HandOrAutoPanelViewModel : ViewModelBase
    {
        /// <summary>
        /// 开始或关闭事件
        /// </summary>
        public DelegateCommand SetOnOrOffCommand { get; set; }
        /// <summary>
        /// 回调消息令牌名称
        /// </summary>
        private string CallbackFuncation;

        /// <summary>
        /// 关闭当前窗体命令
        /// </summary>
        public DelegateCommand CloseAppCommand { get; set; }
        private TagInfo CurrentTag;

        public HandOrAutoPanelViewModel()
        {
            //初始化关闭命令
            CloseAppCommand = new DelegateCommand()
            {
                ExecuteActionObj = new Action<object>(CloseAppHandler)
            };
            // 开始或关闭事件
            SetOnOrOffCommand = new DelegateCommand()
            {
                ExecuteActionObj = new Action<object>(setOnOrOffCommandHandler)
            };
        }

        /// <summary>
        /// 提供给调用者用来设置回调消息名称
        /// </summary>
        /// <param name="CallbackFuncationName">回调消息令牌名称</param>
        public void SetCallbackFuncationName(string CallbackFuncationName)
        {
            CallbackFuncation = CallbackFuncationName;
        }

        /// <summary>
        /// 开始或关闭事件
        /// </summary>
        /// <param name="obj"></param>
        private void setOnOrOffCommandHandler(object obj)
        {
            //发送结果
            Messenger.Default.Send<string>(obj.ToString(), CallbackFuncation);
            Messenger.Default.Send<NotificationMessage>(new NotificationMessage(this, "HideHandOrAutoPanel"));
        }

        /// <summary>
        /// 退出程序命令处理程序
        /// </summary>
        /// <param name="obj">参数</param>
        private void CloseAppHandler(object obj)
        {
            CurrentTag = null;
            Messenger.Default.Send<NotificationMessage>(new NotificationMessage(this, "HideHandOrAutoPanel"));
        }
    }
}
